package com.u3k.mid;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import com.u3k.app.mid.utils.statistics.StatisticsManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.json.JSONArray;
import org.json.JSONObject;

public class ModuleInfo {
    static String a = ModuleInfo.class.getSimpleName();
    public int libId;
    public long crc32;
    public String libVersion;
    public String e;
    public String libUrl;
    public String name;
    public String h;
    public String i;
    public Map<String, String> j = new HashMap();
    public int isEnable;

    public static ModuleInfo a(JSONObject jSONObject) {
        try {
            ModuleInfo uVar = new ModuleInfo();
            uVar.libId = jSONObject.optInt("libId", 0);
            uVar.crc32 = jSONObject.optLong("libCrc32", 0);
            uVar.isEnable = jSONObject.optInt("enable", 0);
            uVar.libVersion = jSONObject.optString("libVersion");
            uVar.e = "";
            if (jSONObject.has("libUrl")) {
                uVar.libUrl = jSONObject.optString("libUrl");
            }
            uVar.name = jSONObject.optString("name");
            uVar.h = jSONObject.optString("coreClass");
            uVar.i = jSONObject.optString("baseCoreClass");
            uVar.j.clear();
            if (jSONObject.has("publicApis")) {
                JSONArray jSONArray = jSONObject.getJSONArray("publicApis");
                for (int i = 0; i < jSONArray.length(); i++) {
                    JSONObject jSONObject2 = jSONArray.getJSONObject(i);
                    uVar.j.put(jSONObject2.optString("shellApi"), jSONObject2.optString("coreApi"));
                }
            }
            return uVar;
        } catch (Exception e) {
            LogUtils.LogError(a, "createFromJson  JSONException=" + e);
            StatisticsManager.getInstance().logException(ae.a(), e);
            return null;
        }
    }

    private static String a(Map<String, String> map) {
        LogUtils.LogError(a, "composePublicApis");
        if (map == null || map.size() == 0) {
            return "";
        }
        String str = "";
        for (Entry entry : map.entrySet()) {
            str = (str.length() > 0 ? str + "#" : str) + ((String) entry.getKey()) + "#" + ((String) entry.getValue());
        }
        LogUtils.LogError(a, "composePublicApis res=" + str);
        return str;
    }

    private static Map<String, String> a(String str) {
        LogUtils.LogError(a, "parsePublicApis  str=" + str);
        if (TextUtils.isEmpty(str)) {
            LogUtils.LogError(a, "parsePublicApis  str=null");
            return new HashMap();
        }
        String[] split = str.split("#");
        if (split == null) {
            LogUtils.LogError(a, "parsePublicApis  keyValues=null");
            return new HashMap();
        }
        Map<String, String> hashMap = new HashMap();
        LogUtils.LogError(a, "parsePublicApis  keyValues.len=" + split.length);
        for (int i = 0; i < split.length; i += 2) {
            hashMap.put(split[i], split[i + 1]);
        }
        return hashMap;
    }

    public static List<ModuleInfo> b(Context context) {
        List<ModuleInfo> arrayList;
        Cursor cursor = null;
        synchronized (ModuleInfo.class) {
            try {
                LogUtils.LogError(a, "getStoredModuleInfos");
                arrayList = new ArrayList();
                SQLiteDatabase a = an.a(context).a();
                if (a == null) {
                    LogUtils.LogError(a, "getStoredModuleInfos db==null");
                } else {
                    cursor = a.rawQuery("select * from modules_table", null);
                    if (cursor == null) {
                        if (cursor != null) {
                            cursor.close();
                        }
                    } else if (cursor.moveToFirst()) {
                        cursor.moveToFirst();
                        while (!cursor.isAfterLast()) {
                            ModuleInfo uVar = new ModuleInfo();
                            uVar.libId = cursor.getInt(cursor.getColumnIndex("libId"));
                            uVar.isEnable = cursor.getInt(cursor.getColumnIndex("enable"));
                            uVar.crc32 = cursor.getLong(cursor.getColumnIndex("libCrc32"));
                            uVar.libUrl = cursor.getString(cursor.getColumnIndex("libUrl"));
                            uVar.libVersion = cursor.getString(cursor.getColumnIndex("libVersion"));
                            uVar.e = cursor.getString(cursor.getColumnIndex("localLibVersion"));
                            uVar.name = cursor.getString(cursor.getColumnIndex("name"));
                            uVar.h = cursor.getString(cursor.getColumnIndex("coreClass"));
                            uVar.i = cursor.getString(cursor.getColumnIndex("baseCoreClass"));
                            uVar.j = a(cursor.getString(cursor.getColumnIndex("publicApis")));
                            arrayList.add(uVar);
                            LogUtils.LogError(a, "getStoredModuleInfos item=" + uVar.name);
                            cursor.moveToNext();
                        }
                        if (cursor != null) {
                            cursor.close();
                        }
                    } else if (cursor != null) {
                        cursor.close();
                    }
                }
            } catch (Exception e) {
                LogUtils.LogError(a, "getStoredModuleInfos Exception=" + e.getMessage());
                StatisticsManager.getInstance().logException(ae.a(), e);
                if (cursor != null) {
                    cursor.close();
                }
            } catch (Throwable th) {
                Class cls = ModuleInfo.class;
            }
        }
        return arrayList;
    }

    public ModuleInfo a() {
        ModuleInfo uVar = new ModuleInfo();
        uVar.libId = this.libId;
        uVar.crc32 = this.crc32;
        uVar.isEnable = this.isEnable;
        uVar.libVersion = new String(this.libVersion);
        if (this.libUrl != null) {
            uVar.e = new String(this.e);
        }
        if (this.libUrl != null) {
            uVar.libUrl = new String(this.libUrl);
        }
        if (this.name != null) {
            uVar.name = new String(this.name);
        }
        if (this.h != null) {
            uVar.h = new String(this.h);
        }
        if (this.i != null) {
            uVar.i = new String(this.i);
        }
        uVar.j = new HashMap();
        if (this.j != null) {
            uVar.j.putAll(this.j);
        }
        return uVar;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void a(android.content.Context r9) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxRuntimeException: Can't find block by offset: 0x0012 in list [B:8:0x0099]
	at jadx.core.utils.BlockUtils.getBlockByOffset(BlockUtils.java:43)
	at jadx.core.dex.instructions.IfNode.initBlocks(IfNode.java:60)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.initBlocksInIfNodes(BlockFinish.java:48)
	at jadx.core.dex.visitors.blocksmaker.BlockFinish.visit(BlockFinish.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:34)
	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:56)
	at jadx.core.ProcessClass.process(ProcessClass.java:39)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:282)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
	at jadx.api.JadxDecompiler.lambda$appendSourcesSave$0(JadxDecompiler.java:200)
*/
        /*
        r8 = this;
        r1 = 0;
        r0 = com.u3k.mid.an.a(r9);
        r0 = r0.a();
        if (r0 != 0) goto L_0x0013;
    L_0x000b:
        r0 = a;
        r1 = "save db==null";
        com.u3k.mid.au.b(r0, r1);
    L_0x0012:
        return;
    L_0x0013:
        r2 = new android.content.ContentValues;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.<init>();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "libId";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.b;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = java.lang.Integer.valueOf(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "libCrc32";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.c;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = java.lang.Long.valueOf(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "libUrl";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.libUrl;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "libVersion";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.d;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "localLibVersion";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.e;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "enable";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.isEnable;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = java.lang.Integer.valueOf(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "name";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.name;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "coreClass";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.h;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "baseCoreClass";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.i;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = "publicApis";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.j;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = a(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.put(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3.<init>();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "select * from modules_table where name='";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r8.name;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "'";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.toString();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = 0;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r1 = r0.rawQuery(r3, r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r1 != 0) goto L_0x009e;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
    L_0x0090:
        r3 = "modules_table";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "name";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r0.insert(r3, r4, r2);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r1 == 0) goto L_0x0012;
    L_0x0099:
        r1.close();
        goto L_0x0012;
    L_0x009e:
        r3 = r1.moveToFirst();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r3 != 0) goto L_0x00b2;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
    L_0x00a4:
        r3 = "modules_table";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "name";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r0.insert(r3, r4, r2);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r1 == 0) goto L_0x0012;
    L_0x00ad:
        r1.close();
        goto L_0x0012;
    L_0x00b2:
        r3 = "modules_table";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "name=?";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r5 = 1;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r5 = new java.lang.String[r5];	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r6 = 0;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r7 = r8.name;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r5[r6] = r7;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r0.update(r3, r2, r4, r5);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r1 == 0) goto L_0x0012;
    L_0x00c3:
        r1.close();
        goto L_0x0012;
    L_0x00c8:
        r0 = move-exception;
        r2 = a;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3.<init>();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = "save Exception=";	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r4 = r0.getMessage();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = r3.toString();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        com.u3k.mid.au.b(r2, r3);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r3 = com.u3k.mid.ae.a();	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        r2.logException(r3, r0);	 Catch:{ Exception -> 0x00c8, all -> 0x00f7 }
        if (r1 == 0) goto L_0x0012;
    L_0x00f2:
        r1.close();
        goto L_0x0012;
    L_0x00f7:
        r0 = move-exception;
        if (r1 == 0) goto L_0x00fd;
    L_0x00fa:
        r1.close();
    L_0x00fd:
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.u3k.mid.u.a(android.content.Context):void");
    }
}
